import type { Preset, Rule } from 'unocss'

const sizeMapping: Record<string, string> = {
  fs: 'font-size',
  fw: 'font-weight',
  lh: 'line-height',
  w: 'width',
  h: 'height',
  p: 'padding',
  pt: 'padding-top',
  pb: 'padding-bottom',
  pl: 'padding-left',
  pr: 'padding-right',
  pa: 'padding',
  m: 'margin',
  mt: 'margin-top',
  mb: 'margin-bottom',
  ml: 'margin-left',
  mr: 'margin-right',
  rd: 'border-radius',
}

function getSizeRules(Mapping: Record<string, string>): Rule[] {
  return Object.keys(Mapping).map((key) => {
    const value = Mapping[key]
    return [new RegExp(`^${key}-(\\d+)$`), ([, d]) => ({ [value]: `${d}rpx` })]
  })
}
export default function basePreset(): Preset {
  return {
    name: 'basePreset',
    rules: getSizeRules(sizeMapping),
    theme: {},
    shortcuts: {
      'row-start': 'flex-row flex justify-start items-center',
      'row-end': 'flex-row flex justify-end items-center',
      'row-center': 'flex-row flex justify-center items-center',
      'row-between': 'flex-row flex justify-between items-center',
      'row-around': 'flex-row flex justify-around items-center',
      'row-evenly': 'flex-row flex justify-evenly items-center',
      'col-start': 'flex-col flex justify-start items-center',
      'col-end': 'flex-col flex justify-end items-center',
      'col-center': 'flex-col flex justify-center items-center',
      'col-between': 'flex-col flex justify-between items-center',
      'col-around': 'flex-col flex justify-around items-center',
      'col-evenly': 'flex-col flex justify-evenly items-center',
      'flex-bc': 'flex justify-between items-center',
      'flex-center': 'flex items-center justify-center',
      'flex-start': 'flex items-center justify-start',
    },
  }
}
